﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using XLua;
public class Lesson2_Loader : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        LuaEnv env = new LuaEnv();

        //重新定位路径的方法 
        //可以自定义加载lua文件的规则
        env.AddLoader(MyLoader);
        
        env.DoString("require('Main')");
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private byte[] MyLoader(ref string filePath)
    {
        //仅编辑器内有效
        var path = Application.dataPath + "/Lua/" + filePath + ".lua";

        if (File.Exists(path))
        {
            return File.ReadAllBytes(path);
        }
        else
        {
            Debug.Log("MyLoader重定向失败，文件名为"+filePath);
        }
        
        return null;
    }
}
